/**
 * @author ${baseInfo.user!''}
   @time   ${baseInfo.date!''}
 */
package ${baseInfo.basePackage!''}.dao.${baseInfo.moduleName!''};

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ct.common.dao.DaoSupport;
import com.ct.common.dto.PageDto;
import ${wholeClassName!''};

@Repository("${baseInfo.objectName!''}Dao")
@Transactional
public class ${baseInfo.className!''}Dao implements DaoSupport<${baseInfo.className!''}>{

	private static Logger logger = LoggerFactory.getLogger(${baseInfo.className!''}Dao.class);

	@Resource(name = "sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	public final static String ${baseInfo.className!''}Mapper = ${baseInfo.className!''}.class.getName() + "Mapper.";
	
	
	@Override
	public int save(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.sqlSessionTemplate.insert(${baseInfo.className!''}Mapper + "insert", ${baseInfo.objectName!''});
	}
	
	
	@Override
	public int update(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.sqlSessionTemplate.update(${baseInfo.className!''}Mapper + "update", ${baseInfo.objectName!''});
	}
	
	public int updateById(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.sqlSessionTemplate.update(${baseInfo.className!''}Mapper + "updateById", ${baseInfo.objectName!''});
	}
	
	@Override
	public int insertBatch(List<${baseInfo.className!''}> list) {
		return this.sqlSessionTemplate.insert(${baseInfo.className!''}Mapper + "insertBatch", list);
	}

	@Override
	public int deleteById(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.sqlSessionTemplate.delete(${baseInfo.className!''}Mapper + "delete", ${baseInfo.objectName!''});
	}

	@Override
	public int count(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.sqlSessionTemplate.selectOne(${baseInfo.className!''}Mapper + "count", ${baseInfo.objectName!''});
	}

	@Override
	public ${baseInfo.className!''} selectOne(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.sqlSessionTemplate.selectOne(${baseInfo.className!''}Mapper + "select", ${baseInfo.objectName!''});
	}

	@Override
	public List<${baseInfo.className!''}> selectList(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.sqlSessionTemplate.selectList(${baseInfo.className!''}Mapper + "select", ${baseInfo.objectName!''});
	}

	@Override
	public List<${baseInfo.className!''}> selectAll() {
		return this.sqlSessionTemplate.selectList(${baseInfo.className!''}Mapper + "selectAll");
	}

	@Override
	public PageDto selectByPage(int currentPage, int pageSize ,Map<String,Object> paramsMap) {
		int totalSize = this.sqlSessionTemplate.selectOne(${baseInfo.className!''}Mapper + "selectByPageTotalSize",paramsMap);
		
		int startRow = (currentPage - 1) * pageSize;
		paramsMap.put("pageSize", pageSize);
		paramsMap.put("startRow", startRow);
		List<${baseInfo.className!''}> list =  this.sqlSessionTemplate.selectList(${baseInfo.className!''}Mapper + "selectByPage", paramsMap);
		
		PageDto pageDto = PageDto.genPageDto(currentPage, pageSize, totalSize, list);
		return pageDto;
	}
	

	@Override
	public ${baseInfo.className!''} getById(Serializable id) {
		return this.sqlSessionTemplate.selectOne(${baseInfo.className!''}Mapper + "selectByID", id);
	}
	
	public int deleteByProperty(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.sqlSessionTemplate.delete(${baseInfo.className!''}Mapper + "deleteByProperty", ${baseInfo.objectName!''});
	}
	
	public List<${baseInfo.className!''}> selectPageAll(Map<String, Object> paramsMap) {
		return this.sqlSessionTemplate.selectList(${baseInfo.className!''}Mapper + "selectPageAll",paramsMap);
	}
	
	public int deleteIds(List<Long> list) {
		return this.sqlSessionTemplate.delete(${baseInfo.className!''}Mapper + "deleteIds", list);
	}
}	
